﻿using IBatisNet.DataMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common
{
    public  class IBatisFun
    {
        public static int Insert<T>(string statement, T t)
        {
            ISqlMapper iSqlMapper = Mapper.Instance();
            if (iSqlMapper != null)
            {
                return (int)iSqlMapper.Insert(statement, t);
            }
            return -1;
        }

        public static int Update<T>(string statementName, T t)
        {
            ISqlMapper iSqlMapper = Mapper.Instance();
            if (iSqlMapper != null)
            {
                return iSqlMapper.Update(statementName, t);
            }
            return -1;
        }

        public static T QueryForObject<T>(string statementName, int primaryKeyId) where T : class
        {
            ISqlMapper iSqlMapper = Mapper.Instance();
            if (iSqlMapper != null)
            {
                return iSqlMapper.QueryForObject<T>(statementName, primaryKeyId);
            }
            return null;
        }

        public static IList<T> QueryForList<T>(string statementName, object parameterObject = null)
        {
            ISqlMapper iSqMapper = Mapper.Instance();
            if (iSqMapper != null)
            {
                return iSqMapper.QueryForList<T>(statementName, parameterObject);
            }
            return null;
        }
        public static int QueryForCount(string statementName, object parameterObject = null)
        {
            ISqlMapper iSqMapper = Mapper.Instance();
            if (iSqMapper != null)
            {
                return iSqMapper.QueryForList(statementName, parameterObject).Count;
            }
            return -1;
        }
    }
}
